//
//  ZLWebViewController.swift
//  ZLWeibo
//
//  Created by zhanglongtao on 17/1/10.
//  Copyright © 2017年 hanju001. All rights reserved.
//

import UIKit
import SVProgressHUD

class ZLWebViewController: ZLBaseViewController {

    fileprivate lazy var webView = UIWebView(frame: UIScreen.main.bounds)
    var urlString: String? {
        didSet{
            guard let urlString = urlString, let url = URL(string: urlString) else{
                
                return
            }
            
            webView.loadRequest(URLRequest(url: url))
            
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
extension ZLWebViewController {
    
    override func setupTableView() {
        
        navItem.title = "网页"
        view.backgroundColor = UIColor.white
        view.insertSubview(webView, belowSubview: navigationBar)
        webView.scrollView.backgroundColor = UIColor.white
        webView.backgroundColor = UIColor.white
        //设置contentInset
        webView.scrollView.contentInset.top = navigationBar.bounds.height
        webView.scrollView.contentInset.bottom = -navigationBar.bounds.height
        webView.delegate = self
        //05-撰写控制器简单布局 
    }
    
}
extension ZLWebViewController: UIWebViewDelegate {
    
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        SVProgressHUD.show()
        
        return true
    }
    func webViewDidFinishLoad(_ webView: UIWebView) {
        SVProgressHUD.dismiss()
    }
    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
        SVProgressHUD.dismiss()
    }
}
